local extension = Package:new("tyj_heg")
extension.extensionName = "sifu_heg"
extension.game_modes_whitelist = { 'nos_heg_mode', 'new_heg_mode' ,"jbsnew_heg_mode","zhonger_heg_mode"}
local U = require "packages/utility/utility"
local H = require "packages/ol_hegemony/util"
Fk:loadTranslationTable{
  ["tyj_heg"] = "汤圆国战将",
  ["tyj"]='汤圆国战系列'
}
local tyj__zhanggong = General:new(extension, "tyj_heg__zhanggong", "wei", 3,3)
Fk:loadTranslationTable{
  ["tyj_heg__zhanggong"] = "张恭",
  ["#tyj_heg__zhanggong"] = "西域长歌",
  ["designer:tyj_heg__zhanggong"] = "汤圆",
  ["cv:tyj_heg__zhanggong"] = "官方",
  ["illustrator:tyj_heg__zhanggong"] = "B_LEE",
}
local tyj__qianxin_active = fk.CreateActiveSkill{
  name = "#tyj_heg__qianxin_active",
  mute = true,
  visible = false,
  min_card_num = 1,
  target_num = 0,
  card_filter = function(self, to_select, selected)
    if Self:prohibitDiscard(Fk:getCardById(to_select)) then return false end
    if #selected == 0 then
      return true
    else
      return table.every(selected, function(id) return Fk:getCardById(to_select).suit ~= Fk:getCardById(id).suit end)
    end
  end,
}
local tyj__qianxin = fk.CreateTriggerSkill{
  name = "tyj_heg__qianxin",
  events ={fk.EnterDying},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) then
      return H.compareKingdomWith(player,target) and #player:getCardIds('he')>0
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local default_discard = table.find(player:getCardIds{Player.Hand, Player.Equip}, function (id)
      return not player:prohibitDiscard(Fk:getCardById(id))
    end)
    if default_discard == nil then return false end
    local _,ret = room:askForUseActiveSkill(player,"#tyj_heg__qianxin_active","#tyj__qianxin-dis::"..target.id,true)
    if ret and ret.cards and #ret.cards>0 then
      self.cost_data = ret.cards
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data, self.name, player, player)
    data.extra_data = data.extra_data or {}
    local tos = data.extra_data.tyj_heg__qianxin_draw or {}
    table.insertIfNeed(tos,{player.id,#self.cost_data})
    data.extra_data.tyj_heg__qianxin_draw = tos
  end,

  refresh_events = {fk.AskForCardUse,fk.AfterAskForCardUse},
  can_refresh = function (self, event, target, player, data)
    if target == player then
    if event == fk.AfterAskForCardUse then
      return not data.result and data.extra_data and data.extra_data.tyj_heg__qianxin_dis and data.extra_data.tyj_heg__qianxin_dis>0
    else
      local room = player.room
      local dying_event = room.logic:getCurrentEvent()
      if dying_event and dying_event.event ~= GameEvent.SkillEffect then
        local dying = dying_event.data[1]
        if dying then
        local datax = dying.extra_data or {}
        return datax and datax.tyj_heg__qianxin_draw and #datax.tyj_heg__qianxin_draw>0
        end
      end
    end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.AfterAskForCardUse then
      local num = data.extra_data.tyj_heg__qianxin_dis
      if num and num>0 then
      local ids = table.filter(player:getCardIds("he"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end)
      if #ids <= data.extra_data.tyj_heg__qianxin_dis then
        room:throwCard(ids, self.name, player, player)
      else
      room:askForDiscard(player, data.extra_data.tyj_heg__qianxin_dis, data.extra_data.tyj_heg__qianxin_dis, true, self.name, false,nil,"tyj_heg__qianxin-choose:::"..num,false)
      end
    end
    else
      local todis =0
      local dying_event = room.logic:getCurrentEvent()--:findParent(GameEvent.Dying)
      if dying_event then
        local dying = dying_event.data[1]
        local datax = dying.extra_data or {}
        if datax.tyj_heg__qianxin_draw and #datax.tyj_heg__qianxin_draw>0 then
          for _, tos in ipairs(datax.tyj_heg__qianxin_draw) do
            if #tos>0 then
              local to = room:getPlayerById(tos[1])
              if H.compareKingdomWith(player,to) then
                room:drawCards(player,tos[2],self.name)
                todis = todis+tos[2]
              end
            end
          end
        end
      end
      if todis >0 then
        data.extra_data = data.extra_data or {}
        data.extra_data.tyj_heg__qianxin_dis = data.extra_data.tyj_heg__qianxin_dis or 0
        data.extra_data.tyj_heg__qianxin_dis=data.extra_data.tyj_heg__qianxin_dis+todis
      end
    end
  end,
}
local tyj__zhenxing = fk.CreateTriggerSkill{
  name = "tyj_heg__zhenxing",
  events = {fk.Damaged},
  can_trigger = function (self, event, target, player, data)
    return target==player and player:hasSkill(self)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local choices = {"1","2","3","Cancel"}
    local choice = room:askForChoice(player,choices,self.name,"是否发动 镇行 展示牌堆顶的至多三张牌？",false)
    if choice ~= "Cancel" then
      self.cost_data = tonumber(choice)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local getcards = room:getNCards(self.cost_data)
    local showcards = {}
    table.insertTableIfNeed(showcards,getcards)
    if #player:getCardIds('h')>0 then
      table.insertTableIfNeed(showcards,player:getCardIds('h'))
    end
    player:showCards(getcards)
    room:delay(600)
    player:showCards(player:getCardIds('h'))
    room:delay(800)
    local suits = {}
    for _, cid in ipairs(showcards) do
      local c = Fk:getCardById(cid)
      if c.suit and not table.contains(suits,c.suit) then
        table.insertIfNeed(suits,c.suit)
      else
        suits = nil
        break
      end
    end
    if suits ~= nil then
    local toget = {}
    for _, cid in ipairs(showcards) do
      if ((room:getCardOwner(cid)==nil) or(room:getCardOwner(cid)~=player)) or room:getCardArea(cid)~=Card.PlayerHand then
        table.insertIfNeed(toget,cid)
      end
    end
    if #toget>0 then
      room:moveCardTo(toget, Player.Hand, player, fk.ReasonPrey, self.name, "", true)
    end
  end
  local cards = table.filter(getcards, function(id) return room:getCardArea(id) == Card.Processing end)
    room:moveCardTo(cards, Card.DrawPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
  end,
}
tyj__qianxin:addRelatedSkill(tyj__qianxin_active)
tyj__zhanggong:addSkill(tyj__qianxin)
tyj__zhanggong:addSkill(tyj__zhenxing)
Fk:loadTranslationTable{
  ["tyj_heg__qianxin"]="遣信",
  [":tyj_heg__qianxin"]="与你势力相同的角色进入濒死时，你可以弃置任意张花色不同的牌，令与你势力相同的角色因此结算需要使用【桃】时摸等量张牌，若其未使用，其弃置等量张牌。",
  ["#tyj__qianxin-dis"]="是否发动 遣信 弃置任意张牌令即将对 %dest 使用【桃】的同势力角色摸等量张牌？",
  ["#tyj_heg__qianxin_active"]="遣信",
  ["tyj_heg__qianxin-choose"]="遣信：选择 %arg 张牌弃置。",
  ["tyj_heg__zhenxing"]="镇行",
  [":tyj_heg__zhenxing"]="你受到伤害后，可以展示牌堆顶的至多三张牌并展示手牌，若这些牌花色均不相同，你获得这些牌。",
  ["~tyj_heg__zhanggong"]="大漠孤烟，孤立无援啊。",
  ["$tyj_heg__qianxin1"]="兵困绝地，将至如归！",
  ["$tyj_heg__qianxin2"]="临危之际，速速来援！",
  ["$tyj_heg__zhenxing1"]="东征西讨，募军百里挑一。",
  ["$tyj_heg__zhenxing2"]="众口铄金，积毁销骨。",
}
local tyj__xuangongzhu = General(extension, "tyj_heg__xuangongzhu", "wei", 3,3,General.Female)
Fk:loadTranslationTable{
["tyj_heg__xuangongzhu"] = "宣公主",
["#tyj_heg__xuangongzhu"] = "卿舞驱惘",
["designer:tyj_heg__xuangongzhu"] = "汤圆",
["cv:tyj_heg__xuangongzhu"] = "官方",
["illustrator:tyj_heg__xuangongzhu"] = "热图文化",
}
local tyj__qingwu = fk.CreateActiveSkill{
  name = "tyj_heg__qingwu",
  anim_type = "tyj_heg__qingwu",
  card_num = 0,
  target_num = 2,
  times = function(self)
    return Self.phase == Player.Play and 1 - Self:usedSkillTimes(self.name, Player.HistoryPhase) or -1
  end,
  prompt = "卿舞：你选择选择两名角色，将先选的角色装备区域内一张牌移动至后先选的角色的装备区内，然后前者视为对后者使用【杀】",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected)
    local target = Fk:currentRoom():getPlayerById(to_select)
    if target then
    if #selected == 0 then
      return #target:getCardIds('e')>0 and #table.filter(target:getCardIds('e'),function (cid)
        local c = Fk:getCardById(cid)
        return c.sub_type == Card.SubtypeWeapon
      end)>0
    elseif #selected == 1 then
      local cardx = table.filter(Fk:currentRoom():getPlayerById(selected[1]):getCardIds('e'),function (cid)
        local c = Fk:getCardById(cid)
        return c.sub_type ~= Card.SubtypeWeapon
      end)
      return  Fk:currentRoom():getPlayerById(selected[1]):canMoveCardsInBoardTo(target,'e',cardx)
    end
  end
  return false
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cardx = table.filter(room:getPlayerById(effect.tos[1]):getCardIds('e'),function (cid)
      local c = Fk:getCardById(cid)
      return c.sub_type ~= Card.SubtypeWeapon
    end)
    room:askForMoveCardInBoard(player, room:getPlayerById(effect.tos[1]), room:getPlayerById(effect.tos[2]), self.name,'e',room:getPlayerById(effect.tos[1]),cardx)
    if room:getPlayerById(effect.tos[1]):isAlive() and room:getPlayerById(effect.tos[2]):isAlive() then
      local use=room:useVirtualCard("slash", nil, room:getPlayerById(effect.tos[1]), room:getPlayerById(effect.tos[2]), self.name,true)
      if player:isAlive() then
        local to = room:getPlayerById(use.from)
      local all_choices = {"弃置牌","令其摸牌"}
      local choices = {}
      if #player:getCardIds('he')>0 then
        table.insert(choices,"弃置牌")
      end
      if use.damageDealt and to:isAlive() then
        table.insert(choices,"令其摸牌")
      end
      if #choices >0 then
        local choice = room:askForChoice(player, choices, self.name,"卿舞：你须选择一项执行",false,all_choices)
        if choice == "令其摸牌" then
          to:drawCards(2,self.name)
        else
          room:askForDiscard(player, 2, 2, true, self.name, false,nil,"卿舞：你需弃置两张手牌",false)
        end
      end
    end
  end
  end,
}
local tyj__rongru = fk.CreateTriggerSkill{
  name = "tyj_heg__rongru",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          if move.to == player.id and move.toArea == Player.Hand and move.moveReason == fk.ReasonDraw then
            return #move.moveInfo>1
          end
          if move.from == player.id and move.moveReason == fk.ReasonDiscard then
            for _, info in ipairs(move.moveInfo) do
              if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) then
                return #move.moveInfo>1
              end
            end
          end
        end
      end
    end
  end,
  on_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          if move.to == player.id and move.toArea == Player.Hand and move.moveReason == fk.ReasonDraw then
            local cards = {}
            table.forEach(move.moveInfo, function(info)
                table.insert(cards, info.cardId)
            end)
            if # cards>0 then
              self:doCost(event, target, player, {type = "draw",cids = cards})
            end
          end
          if move.from == player.id and move.moveReason == fk.ReasonDiscard then
            local cards = {}
            table.forEach(move.moveInfo, function(info)
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                table.insert(cards, info.cardId)
              end
            end)
            if # cards>0 then
              self:doCost(event, target, player, {type = "dis",cids = cards})
            end
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local str = nil 
    if room:askForSkillInvoke(player,self.name) then
    if data.type == "dis" then
      str = "融濡：选择你弃置的一张牌，然后交给一名角色"
    else
      str = "融濡：选择你摸的一张牌，然后交给一名角色"
    end
    local get = room:askForCardsChosen(player, player, 1,1, {
      card_data = {
        { "pile_discard", data.cids }
      }
    }, self.name,str)
    if #get>0 then
      self.cost_data = get[1]
      return true
    end
  end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local c = Fk:getCardById(self.cost_data)
    local tos = room:getOtherPlayers(player)
    if # tos >0 then
    local to = room:askForChoosePlayers(player,table.map(tos,Util.IdMapper),1,1,"#tyj__rongru-choose:::"..c:toLogString(),self.name,false,false)
if #to>0 then
  room:moveCardTo(c.id, Player.Hand,room:getPlayerById(to[1]), fk.ReasonGive, self.name, nil, false, player.id)
end
end
  end,
}
tyj__xuangongzhu:addSkill(tyj__qingwu)
tyj__xuangongzhu:addSkill(tyj__rongru)
Fk:loadTranslationTable{
  ["tyj_heg__qingwu"]="卿舞",
  [":tyj_heg__qingwu"]="出牌阶段限一次，你可以将一名角色装备区内的一张武器牌移动至另一名角色的装备区内，令前者视为对后者使用【杀】，然后你须弃置两张牌或令因此造成伤害的角色摸两张牌。",
  ["tyj_heg__rongru"]="融濡",
  [":tyj_heg__rongru"]="你一次性摸或弃置至少两张牌后，可以将其中一张牌交给一名其他角色。",
  ["#tyj__rongru-choose"]="融濡：将 %arg 交给一名角色。",
  ["$tyj_heg__qingwu1"] = "天家贵胄，福泽四海。",
  ["$tyj_heg__qingwu2"] = "虽豺狼当道，虎豹哮林，妾亦生死相随。",
  ["$tyj_heg__rongru1"] = "辅车相依，比翼双飞。",
  ["$tyj_heg__rongru2"] = "情投意合，相濡以沫。",
  ["~tyj_heg__xuangongzhu"] = "元凯，我去也……",
}
local tyj__guanqiujian = General:new(extension, "tyj_heg__guanqiujian", "wei", 4,4)
tyj__guanqiujian:addCompanions({"ze_heg__wenqin"})
    Fk:loadTranslationTable{
      ["tyj_heg__guanqiujian"] = "毌丘俭",
      ["#tyj_heg__guanqiujian"] = "镌功海东",
      ["designer:tyj_heg__guanqiujian"] = "汤圆",
      ["cv:tyj_heg__guanqiujian"] = "官方",
      ["illustrator:tyj_heg__guanqiujian"] = "凝聚永恒",
    }
tyj__guanqiujian.mainMaxHpAdjustedValue = -1
local tyj__zhengrong = fk.CreateTriggerSkill{
  name = "tyj_heg__zhengrong",
  anim_type = "offensive",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and ((player:usedSkillTimes(self.name,Player.HistoryTurn)==0) or player:usedSkillTimes("tyj_heg__hongju",Player.HistoryTurn)>0) and #data.to:getCardIds('ej')>0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"tyj_heg__zhengrong_discard"}
    if data.to:canMoveCardsInBoardTo(player, nil) then
      table.insert(choices, 1, "tyj_heg__zhengrong_move")
    end
    local choice = room:askForChoice(player, choices, self.name)
    if choice == "tyj_heg__zhengrong_move" then
      room:askForMoveCardInBoard(player, data.to, player, self.name, nil, data.to)
    else
      local id = room:askForCardChosen(player, data.to, "ej", self.name)
      room:throwCard({id}, self.name, data.to, player)
    end
  end
}
local tyj__hongju = fk.CreateTriggerSkill{
  name = "tyj_heg__hongju",
  anim_type = "big",
  frequency = Skill.Limited,
  relate_to_place = "m",
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
  return target == player and player:hasSkill(self) and player.phase == Player.Start and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and #player:getCardIds('ej')>0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cards=player:getCardIds('ej')
    local num =#cards*2
    room:throwCard(cards,self.name,player,player)
    if num>0 then
    local drawed = room:drawCards(player,num,self.name,nil,"@@tyj_heg__hongju_bypass-inhand-turn")
    player:showCards(drawed)
    end
  end,
}
local tyj__hongju_prohibit = fk.CreateTargetModSkill{
  name = "#tyj_heg__hongju_prohibit",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and card:getMark("@@tyj_heg__hongju_bypass-inhand-turn") > 0
  end,
}
tyj__hongju:addRelatedSkill(tyj__hongju_prohibit)
tyj__guanqiujian:addSkill(tyj__zhengrong)
tyj__guanqiujian:addSkill(tyj__hongju)
Fk:loadTranslationTable{
  ["tyj_heg__zhengrong"]="征荣",
  [":tyj_heg__zhengrong"]="每回合限一次，当你造成伤害时，你可以移动一名受伤角色场上的一张牌至你的区域内或弃置之。",
  ["tyj_heg__zhengrong_discard"]="弃置其场上的一张牌",
  ["tyj_heg__zhengrong_move"]="将其场上一张牌移动至你的区域内",
  ["tyj_heg__hongju"]="鸿举",
  [":tyj_heg__hongju"]="主将技，限定技，此武将牌上单独的阴阳鱼数-1。准备阶段，你可以弃置你场上的牌，摸两倍的牌并展示之，你本回合使用这些牌与〖征荣〗均无次数限制。",
  ["#tyj_heg__hongju_prohibit"]="鸿举",
  ["@@tyj_heg__hongju_bypass-inhand-turn"]="鸿举",
  ["$tyj_heg__zhengrong1"]="功名利禄马前取，封狼居胥万户侯。",
  ["$tyj_heg__zhengrong2"]="枭胡首，筑京观，昭万里。",
  ["$tyj_heg__hongju1"]="举烽火为号，你我共襄义举！",
  ["$tyj_heg__hongju2"]="老贼久负不臣之心，某，先攻为敬！",
  ["~tyj_heg__guanqiujian"]="感明帝之恩，无憾。",
}
local tyj__huojun = General(extension, "tyj_heg__huojun", "shu", 4,4)
Fk:loadTranslationTable{
  ["tyj_heg__huojun"] = "霍峻",
  ["#tyj_heg__huojun"] = "葭萌雄狮",
  ["designer:tyj_heg__huojun"] = "汤圆",
  ["cv:tyj_heg__huojun"] = "官方",
  ["illustrator:tyj_heg__huojun"] = "热图文化",
}
    local tyj__fenrui = fk.CreateActiveSkill{
      name = "tyj_heg__fenrui",
      anim_type = "offensive",
      card_num = 1,
      target_num = 0,
      prompt = "#tyj_heg__fenrui",
      times = function(self)
        return Self.phase == Player.Play and 1 - Self:usedSkillTimes(self.name, Player.HistoryPhase) or -1
      end,
      can_use = function (self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isNude()
      end,
      card_filter = function(self, to_select, selected)
        local card = Fk:getCardById(to_select)
        return #selected == 0 and card.type == Card.TypeEquip --and not Self:prohibitDiscard(to_select)
      end,
      target_filter = Util.FalseFunc,
      on_use = function(self, room, effect)
        local from = room:getPlayerById(effect.from)
        if from:isAlive() then
        --room:throwCard(effect.cards, self.name, from, from)
        room:recastCard(effect.cards, room:getPlayerById(effect.from), self.name)
        if from:isAlive() then
        local card
        local cards={}
        local cardstouse = {}
        while true do
          if from:isAlive() then
          local id = room:getNCards(1)[1]
          room:moveCardTo(id, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, from.id)
          table.insert(cardstouse, id)
          room:delay(300)
          local c = Fk:getCardById(id)
          if c.trueName == "slash" then
            card = c
            room:delay(500)
            break
          else
            table.insert(cards, id)
          end
        else break end
        end
        if from:isAlive() and room:getCardOwner(card.id)==nil then
        room:moveCardTo(card.id, Player.Hand,from, fk.ReasonPrey, self.name, nil, true, from.id)
        end
        if from:isAlive() and #cardstouse>0 then
          U.askForUseRealCard(room, from,cardstouse, nil, self.name,"奋锐：你可以使用亮出的一张牌", {expand_pile =table.filter(cardstouse,function(cid) return room:getCardOwner(cid)~=from and room:getCardArea(cid)~=Card.PlayerHand end), extra_use = true},false)
        end
        cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
    room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, from.id)
      end
    end
      end,
    }
    tyj__huojun:addSkill(tyj__fenrui)
    Fk:loadTranslationTable{
      ["tyj_heg__fenrui"]="奋锐",
      [":tyj_heg__fenrui"]="出牌阶段限一次，你可以重铸一张装备牌以亮出牌堆顶的牌直到亮出【杀】，然后你获得此【杀】并可以使用一张因此亮出的牌（不计入次数）。",
      ["#tyj_heg__fenrui"]="奋锐：你可以重铸一张装备牌，从牌堆顶翻找一张【杀】并使用翻出的一张牌。",
      ["$tyj_heg__fenrui1"]="善守者亦善攻，不可死守。",
      ["$tyj_heg__fenrui2"]="璋军疲敝，可伺机而攻。",
      ["~tyj_heg__huojun"] = "蒙君知遇，奈何早薨。",
    }
local tyj__wuban = General(extension, "tyj_heg__wuban", "shu", 4,4)
tyj__wuban:addCompanions({"zhonger_st_heg__weiyan"})
Fk:loadTranslationTable{
["tyj_heg__wuban"] = "吴班",
["#tyj_heg__wuban"] = "笃进豪侠",
["designer:tyj_heg__wuban"] = "汤圆",
["cv:tyj_heg__wuban"] = "官方",
["illustrator:tyj_heg__wuban"] = "匠人绘",
}
local tyj__jintao = fk.CreateTriggerSkill{
  anim_type = "drawcard",
  name = "tyj_heg__jintao",
  events = {fk.EventPhaseEnd},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and target == player and player.phase == Player.Play then
        local card = Fk:cloneCard("slash")
        local card_skill = card.skill
        local status_skills = Fk:currentRoom().status_skills[TargetModSkill] or Util.DummyTable
        for _, skill in ipairs(status_skills) do
          if skill:bypassTimesCheck(player, card_skill, Player.HistoryPhase, card, nil) then return false end
        end
        if player:usedCardTimes("slash", Player.HistoryPhase) >= card_skill:getMaxUseTime(player, Player.HistoryPhase, card, nil) then
          return true
        end
      end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player,self.name,nil,"#tyj__jintao-invoke")
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:drawCards(player,2,self.name)
    local mark = player:getMark("@tyj_heg__jintao-extraslash")
    mark = mark+1
    room:setPlayerMark(player,"@tyj_heg__jintao-extraslash",mark)
  end,
}
local tyj__jintao_targetmod = fk.CreateTargetModSkill{
  name = "#tyj_heg__jintao_targetmod",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("@tyj_heg__jintao-extraslash") > 0 and scope == Player.HistoryPhase then
      return player:getMark("@tyj_heg__jintao-extraslash")
    end
  end,
}
local tyj__jintao_maxhand = fk.CreateMaxCardsSkill{
  name = "#tyj__jintao_maxhand",
  exclude_from = function(self, player, card)
    return player:hasShownSkill("tyj_heg__jintao") and card.trueName == 'slash'
  end,
}
tyj__jintao:addRelatedSkill(tyj__jintao_targetmod)
tyj__jintao:addRelatedSkill(tyj__jintao_maxhand)
tyj__wuban:addSkill(tyj__jintao)
Fk:loadTranslationTable{
  ["tyj_heg__jintao"]="进讨",
  [":tyj_heg__jintao"]="你的【杀】不计入手牌上限。出牌阶段结束时，若你本阶段使用【杀】的次数不小于次数上限，你可以摸两张牌并令此上限+1。",
  ["#tyj__jintao-invoke"]="是否发动 进讨 摸两张牌并令使用【杀】的次数上限+1？",
  ["@tyj_heg__jintao-extraslash"]="进讨",
  ["#tyj__jintao_maxhand"]="进讨",
  ["$tyj_heg__jintao1"] = "一雪前耻，誓报前仇！",
  ["$tyj_heg__jintao2"] = "量敌而进，直讨吴境！",
  ["~tyj_heg__wuban"] = "恨……杀不尽吴狗！",
}

local tyj__furong = General:new(extension, "tyj_heg__furong", "shu", 4,4)
Fk:loadTranslationTable{
  ["tyj_heg__furong"] = "傅肜",
  ["#tyj_heg__furong"] = "弈世忠烈",
  ["designer:tyj_heg__furong"] = "汤圆",
  ["cv:tyj_heg__furong"] = "官方",
  ["illustrator:tyj_heg__furong"] = "鬼画府",
}
local tyj__liechi = fk.CreateViewAsSkill{
    name="tyj_heg__liechi",
    anim_type = "control",
    pattern = "peach",
    prompt = function ()
      return "烈斥：你可以弃置一名角色的一张牌，然后以一种方式使用【桃】"
    end,
    card_num = 0,
    card_filter = Util.FalseFunc,
    view_as = function(self, cards)
      local card = Fk:cloneCard("peach")
      card.skillName = self.name
      return card
    end,
    before_use = function (self, player, use)
      local room = player.room
      local tot = table.filter(room.alive_players,function (p)
        return #p:getCardIds('he')>0
      end)
      if #tot>0 then
        local to = room:askForChoosePlayers(player,table.map(tot,Util.IdMapper),1,1,"烈斥：选择要被弃牌的角色",self.name,false,false)
        if #tot>0 and #room:getPlayerById(to[1]):getCardIds('he')>0 then
          local choices={}
          local cancards = {}
          local target = room:getPlayerById(to[1])
          local cards = room:askForCardChosen(player,target,'he',self.name,"tyj_heg__liechi-discard::"..target.id)
      if cards and target:isAlive() then
      room:throwCard(cards,self.name,target,player)
      if #player:getCardIds('he')>0 then
        for _, cid in ipairs(player:getCardIds('he')) do
          if Fk:getCardById(cid).trueName==Fk:getCardById(cards).trueName then
            local yesable = true
            local peach = Fk:cloneCard("peach")
            peach.skillName = self.name
            peach:addSubcard(cid)
            if player:prohibitUse(peach) then
              break
            end
            if use.tos ~= nil then
            for n, pid in ipairs(use.tos) do
            if
              (player:isProhibited(room:getPlayerById(pid[1]), peach))
           then
            yesable = false
            break
            end
          end
        end
          if yesable == true then
            table.insertIfNeed(cancards,cid)
          end
          end
          end
          if #cancards>0 then
            table.insert(choices,"#tyj_heg__leichi-view_as")
          end
        end
        table.insert(choices,"#tyj_heg__leichi-remove")
        local all_choices = {"#tyj_heg__leichi-view_as","#tyj_heg__leichi-remove"}
        local choice = room:askForChoice(player,choices,self.name,"烈斥：选择你要使用这张【桃】的方式",true,all_choices)
        if choice == "#tyj_heg__leichi-remove" then
          local choicesx = {}
          local all_choicesx = {"主将","副将"}
          if H.getHegLord(Fk:currentRoom(),player)~=player and H.hasGeneral(player, false) then
            table.insert(choicesx,"主将")
          end
          if H.hasGeneral(player, true) then
            table.insert(choicesx,"副将")
          end
          local choicex = room:askForChoice(player,choicesx,self.name,"烈斥：移除你的一张武将牌",false,all_choicesx)
          if choicex == "主将" then
            H.removeGeneral(room, player,false)
            return
          else
            H.removeGeneral(room, player,true)
            return
          end
        else
          local get = room:askForCardsChosen(player, player, 1,1, {
            card_data = {
              { "可选牌", cancards }
            }
          }, self.name, "烈斥：选择要被当【桃】用的牌")
          if #get>0 then
            use.card:addSubcard(get[1])
            return
          end
        end
      end
      end
    end
    return "tyj_heg__liechi"
    end,
    enabled_at_response = function(self, player, res)
      return
        not res and
        not table.find(Fk:currentRoom().alive_players, function(p) return H.compareKingdomWith(player,p)~=true and p.dying end)
    end,
}
local tyj__liechi_prohibit = fk.CreateProhibitSkill{
  name = "#tyj_heg__liechi_prohibit",
  is_prohibited = function(self, from, to, card)
    if from:hasSkill("tyj_heg__liechi", true) then
      return table.contains(card.skillNames, "tyj_heg__liechi") and H.compareKingdomWith(from,to)~=true
    end
  end,
}
tyj__liechi:addRelatedSkill(tyj__liechi_prohibit)
tyj__furong:addSkill(tyj__liechi)
Fk:loadTranslationTable{
  ["tyj_heg__liechi"]="烈斥",
  [":tyj_heg__liechi"]="你需要对与你势力相同的角色使用【桃】时，你可以弃置一名角色的一张牌然后选择一项：1.将一张同名牌当【桃】使用；2.移除一张武将牌视为使用一张【桃】。",
  ["#tyj_heg__liechi-discard"]="烈斥：弃置 %dest 的一张牌。",
  ["#tyj_heg__leichi-view_as"]="将牌当【桃】",
  [":#tyj_heg__leichi-view_as"]="选择一张与弃置的牌牌名相同的牌，将这张牌当【桃】使用。",
  ["#tyj_heg__leichi-remove"]="移除武将牌",
  [":#tyj_heg__leichi-remove"]="移除你的一张武将牌，视为使用【桃】。",
  ["~tyj_heg__furong"]="吴狗！何有汉将军降者！",
  ["$tyj_heg__liechi1"]="老夫一息尚存，吴狗便动不得主公分毫！",
  ["$tyj_heg__liechi2"]="吴狗何在，大汉将军傅肜在此！",
}

local tyj__panshu = General(extension, "tyj_heg__panshu", "wu", 3,3,General.Female)
tyj__panshu:addCompanions({"zhonger_st_heg__sunquan"})
Fk:loadTranslationTable{
["tyj_heg__panshu"] = "潘淑",
["#tyj_heg__panshu"] = "婉转燕尔",
["designer:tyj_heg__panshu"] = "静谦&汤圆",
["cv:tyj_heg__panshu"] = "官方",
["illustrator:tyj_heg__panshu"] = "君桓文化",
}
local tyj__jinzhi = fk.CreateTriggerSkill{
  name = "tyj_heg__jinzhi",
  anim_type = "drawcard",
events = { fk.AfterCardsMove},
can_trigger = function(self, event, target, player, data)
if player:hasSkill(self) then
  if event == fk.CardUseFinished then
    return target == player and data.card.type == Card.TypeEquip
  else
    local equipnum = #player:getCardIds("e")
    for _, move in ipairs(data) do
      for _, info in ipairs(move.moveInfo) do
        if move.from == player.id and info.fromArea == Card.PlayerEquip then
          equipnum = equipnum + 1
        elseif move.to == player.id and move.toArea == Card.PlayerEquip then
          equipnum = equipnum - 1
        end
      end
    end
    if #player:getCardIds("e") ~= equipnum then
      --[[local ecards = player:getCardIds("e")
      if #ecards ~= 0 then
      local suits = {}
      for _, cid in ipairs(player:getCardIds("e")) do
        local c = Fk:getCardById(cid)
        if table.contains(suits,c.suit) then
          return false
        else
          table.insertIfNeed(suits,c.suit)
        end
      end
      return true
      end--]]
      return true
    end
  end
end
end,
on_cost = function (self, event, target, player, data)
local room = player.room
local tos = table.filter(room.alive_players,function(p) return #p:getCardIds('he')>0 end )
if #tos>0 then
local to = room:askForChoosePlayers(player,table.map(tos,Util.IdMapper),1,1,"#tyj__jinzhi-invoke",self.name,true,false)
if #to>0 then
  self.cost_data = to[1]
  return true
end
end
end,
on_use = function (self, event, target, player, data)
local room = player.room
local to = room:getPlayerById(self.cost_data)
room:doIndicate(player.id,{self.cost_data})
if to:isAlive() and #to:getCardIds('he') >0  then
   local disedid = room:askForDiscard(to, 1, 1, true, self.name, false,nil,"锦织：你需要弃置一张牌",false)
   if #disedid==1 and #player:getCardIds('e')>0 then
    local realid =disedid[1]
    for _, cid in ipairs(player:getCardIds('e')) do
      if Fk:getCardById(cid).suit == Fk:getCardById(realid).suit then
        to:drawCards(1,self.name)
        break
      end
    end
   end
end
end,
}
local tyj__weiyi =fk.CreateTriggerSkill{
  name = "tyj_heg__weiyi",
  anim_type = "control",
events = {fk.BeforeDrawCard},
can_trigger = function(self, event, target, player, data)
return H.compareKingdomWith(player,target) and #target:getCardIds('e') < #player:getCardIds('e') and player:hasSkill(self) and data.skillName~=self.name and data.num > 0 and target.phase == Player.Draw
end,
on_cost = function (self, event, target, player, data)
local room = player.room
return room:askForSkillInvoke(player, self.name, nil,"#tyj_heg__weiyi-invoke::"..target.id..":"..data.num)
end,
on_use = function (self, event, target, player, data)
local room = player.room
room:drawCards(player,data.num,self.name)
if #player:getCardIds('he')>0 then
  local cardsm = room:askForCard(player, math.min(#player:getCardIds('he'),data.num), math.min(#player:getCardIds('he'),data.num), true, self.name, false, ".","#tyj_heg__weiyi-give::"..target.id..":"..data.num)
  if #cardsm>0 then
    room:moveCardTo(cardsm, Player.Hand,target, fk.ReasonGive, self.name, nil, false, player.id)
  end
end
data.num = 0
end,
}
tyj__panshu:addSkill(tyj__jinzhi)
tyj__panshu:addSkill(tyj__weiyi)
Fk:loadTranslationTable{
["#tyj_heg__jinzhi"]="锦织",
["tyj_heg__jinzhi"]="锦织",
[":tyj_heg__jinzhi"]="当你装备区内的牌数变化后，你可令一名角色弃置一张牌，若你装备区有与此牌同花色的牌，其摸一张牌。",
["#tyj__jinzhi-invoke"]="是否发动 锦织 令一名角色弃置一张牌？",
["tyj_heg__weiyi"]="威仪",
[":tyj_heg__weiyi"]="与你势力相同的角色因摸牌阶段摸牌时，若其装备区内的牌数小于你，你可以改为由你摸牌，若如此做，你需要交给其等量的牌。",
["#tyj_heg__weiyi-invoke"]="是否发动 威仪 令你摸 %dest 即将摸的 %arg 张牌？",
["#tyj_heg__weiyi-give"]="威仪：你需要交给 %dest %arg 张牌",
["$tyj_heg__weiyi1"] = "无威仪者，不可奉社稷。",
["$tyj_heg__weiyi2"] = "有威仪者，进止雍容。",
["$tyj_heg__jinzhi1"] = "织锦为旗，以扬威仪。",
["$tyj_heg__jinzhi2"] = "坐而织锦，立则为仪。",
["~tyj_heg__panshu"] = "本为织女，幸蒙帝垂怜……",
}
    local tyj__sunluban = General(extension, "tyj_heg__sunluban", "wu", 3,3,General.Female)
Fk:loadTranslationTable{
  ["tyj_heg__sunluban"] = "孙鲁班",
  ["#tyj_heg__sunluban"] = "为虎作伥",
  ["designer:tyj_heg__sunluban"] = "汤圆",
  ["cv:tyj_heg__sunluban"] = "官方",
  ["illustrator:tyj_heg__sunluban"] = "FOOLTOWN",
}
tyj__sunluban:addCompanions({"zhonger_st_heg__sunquan"})
    local tyj__zenhui = fk.CreateTriggerSkill{
      name="tyj_heg__zenhui",
      events={fk.AfterCardTargetDeclared},
      anim_type = "control",
      can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and H.compareKingdomWith(player,target) and (data.card:isCommonTrick() or data.card.trueName == 'slash') and
          table.every(player.room:getOtherPlayers(target), function (p) return #target:getCardIds('e') >= #p:getCardIds('e') end) and data.card.trueName ~= "threaten_emperor"
          and data.card.trueName ~= "heg_zhaoshu"
      end,
      on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = U.getUseExtraTargets(room, data)
        if #targets == 0 then return false end
        local tos = room:askForChoosePlayers(player, targets, 1, 1, "#tyj__zenhui_target:::"
    ..data.card:toLogString(), self.name, true)
    if #tos > 0 then 
      self.cost_data = tos[1]
      return true
     end
      end,
      on_use = function(self, event, target, player, data)
        local room = player.room
        local tos = self.cost_data
        table.insert(data.tos, {tos})
        room:sendLog{ type = "#AddTargetsBySkill", from = target.id, to = {tos}, arg = self.name, arg2 = data.card:toLogString() }
        local to = room:getPlayerById(tos)
        if to:isAlive() and #target:getCardIds('he')>0 then
          local card = room:askForCardChosen(to, target, "he", self.name,"谮毁：弃置其一张牌")
          room:throwCard({card}, self.name, target, player)
      end
      end,
    }
    local tyj__jiaojin_active = fk.CreateActiveSkill{
      name = "#tyj_heg__jiaojin_active",
      card_num = 1,
      visible = false,
      mute=true,
      card_filter = function(self, to_select, selected, targets)
        local tos = Self:getMark("tyj_heg__jiaojin_from-phase")
        if tos~=0 then
        return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip and U.canMoveCardIntoEquip(Fk:currentRoom():getPlayerById(tos), to_select, true)
        end
      end,
    }
    local tyj__jiaojin = fk.CreateTriggerSkill{
      name = "tyj_heg__jiaojin",
      anim_type = "offensive",
      events = {fk.DamageInflicted},
      can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
        return target == player and data.from and data.from:isAlive() and #player:getCardIds('he')>0
        end
      end,
      on_cost = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player,"tyj_heg__jiaojin_from-phase",data.from.id)
        local success, dat = player.room:askForUseActiveSkill(player, "#tyj_heg__jiaojin_active", "#tyj_heg__jiaojin-invoke::"..data.from.id, true)
        if success then
          self.cost_data = dat
          room:setPlayerMark(player,"tyj_heg__jiaojin_from-phase",0)
          return true
        end
      end,
      on_use = function (self, event, target, player, data)
        local room = player.room
        local to = data.from
        U.moveCardIntoEquip(room, to, self.cost_data.cards[1], self.name, true, player)
        return true
      end,
    }
    tyj__sunluban:addSkill(tyj__zenhui)
    tyj__jiaojin:addRelatedSkill(tyj__jiaojin_active)
    tyj__sunluban:addSkill(tyj__jiaojin)
    Fk:loadTranslationTable{
      ["tyj_heg__zenhui"]="谮毁",
      [":tyj_heg__zenhui"]="装备区内牌数为全场最大的与你势力相同的角色使用【杀】或普通锦囊牌时，你可以为此牌指定一个额外目标，然后令此目标弃置使用者的一张牌。",
      ["tyj_heg__jiaojin"]="骄矜",
      [":tyj_heg__jiaojin"]="你受到伤害时，可以将一张装备牌置入伤害来源的装备区（替换原装备）以防止之。",
      ["#tyj__zenhui_target"]="是否发动 谮毁 为 %arg 指定一个额外的目标？",
      ["#tyj_heg__jiaojin_active"]="骄矜",
      ["#tyj_heg__jiaojin-invoke"]="是否将一张装备牌置于 %dest 的装备区内以发动 骄矜 来防止此伤害？",
      ["$tyj_heg__zenhui1"]="你可别不识抬举！",
      ["$tyj_heg__zenhui2"]="你也休想置身事外！",
      ["$tyj_heg__jiaojin1"]="是谁借给你的胆子？",
      ["$tyj_heg__jiaojin2"]="就凭你、还想算计于我？！",
      ["~tyj_heg__sunluban"] = "本公主，何罪之有？",
    }
    local tyj__zhuhuan = General:new(extension, "tyj_heg__zhuhuan", "wu", 4,4)
        Fk:loadTranslationTable{
          ["tyj_heg__zhuhuan"] = "朱桓",
          ["#tyj_heg__zhuhuan"] = "濡须拒天",
          ["designer:tyj_heg__zhuhuan"] = "汤圆",
          ["cv:tyj_heg__zhuhuan"] = "官方",
          ["illustrator:tyj_heg__zhuhuan"] = "XXX",
        }
        local tyj__jianyou = fk.CreateViewAsSkill{
          name = "tyj_heg__jianyou",
          pattern = "slash,nullification",
          interaction = function()
            local names = {}
            if Fk.currentResponsePattern == nil and Self:canUse(Fk:cloneCard("slash")) then
              table.insertIfNeed(names, "slash")
            else
              for _, name in ipairs({"slash", "nullification"}) do
                if Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(Fk:cloneCard(name)) then
                  table.insertIfNeed(names, name)
                end
              end
            end
            if #names == 0 then return end
            return UI.ComboBox {choices = names}
          end,
          card_filter = function(self, to_select, selected)
            return #selected == 0 and Fk:currentRoom():getCardArea(to_select) ~= Player.Equip and Fk:getCardById(to_select).type == Card.TypeEquip
            and Self:canUseTo(Fk:getCardById(to_select), Self)
          end,
          view_as = function(self, cards)
            if #cards ~= 1 or self.interaction.data == nil then return end
            local card_name = self.interaction.data
            local card = Fk:cloneCard(card_name)
            card.skillName = self.name
            card:setMark(self.name, cards[1])
            return card
          end,
          before_use = function (self, player, use)
            local room = player.room
        local card_id = use.card:getMark(self.name)
        if #table.filter(player:getCardIds(Player.Equip), function (cid)
          return Fk:getCardById(cid).sub_type == Fk:getCardById(card_id).sub_type
        end)>0 then
          use.disresponsiveList = table.map(room.alive_players, Util.IdMapper)
        end
          room:useCard{
            from = player.id,
            tos = {{player.id}},
            card = Fk:getCardById(card_id),
          }
          end,
          enabled_at_response = function(self, player, response)
            return not response and not player:isKongcheng()
          end,
        }
        tyj__zhuhuan:addSkill(tyj__jianyou)
        Fk:loadTranslationTable{
          ["tyj_heg__jianyou"]="蹇诱",
          [":tyj_heg__jianyou"]="你可以使用手牌中的一张装备牌，视为使用【杀】或【无懈可击】。若因此替换了装备，此牌无法被响应。",
          ["$tyj_heg__jianyou1"]="以主制客，占尽优势。",
          ["$tyj_heg__jianyou2"]="反守为攻，直捣黄龙。",
          ["~tyj_heg__zhuhuan"]="我不要，死在这病榻之上。",
        }
local tyj__gongsundu = General(extension, "tyj_heg__gongsundu", "qun", 4,4)
tyj__gongsundu:addCompanions({"tyta_heg__xurong"})
Fk:loadTranslationTable{
["tyj_heg__gongsundu"] = "公孙度",
["#tyj_heg__gongsundu"] = "威戾海东",
["designer:tyj_heg__gongsundu"] = "汤圆",
["cv:tyj_heg__gongsundu"] = "官方",
["illustrator:tyj_heg__gongsundu"] = "匠人绘",
}
local tyj__zhenzhe = fk.CreateTriggerSkill{
name = "tyj_heg__zhenzhe",
events = {fk.Damage},
can_trigger = function (self, event, target, player, data)
if target == player and player:hasSkill(self) then
  return data.card and ((data.card.trueName == 'slash') or data.card.name == "duel") and --[[player.room.logic:getActualDamageEvents(1, function(e)
    return e.data[1].from == player
  end)[1].data[1] == data player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and--]] data.to and data.to:isAlive()
end
end,
on_cost = function (self, event, target, player, data)
local room = player.room
local tos = table.filter(room.alive_players,function (p)
  return  data.to:inMyAttackRange(p) and #p:getCardIds('h')~=math.max(data.to.hp,0)
end)
if #tos > 0 then
  local num = math.max(data.to.hp,0)
  for _, p in ipairs(tos) do
    local cnum = #p:getCardIds('h')-num
    if cnum > 0 then
      room:setPlayerMark(p,"@tyj_heg__zhenzhe-dis",cnum)
      room:setPlayerMark(p,"@tyj_heg__zhenzhe-recover",1)
    else
      room:setPlayerMark(p,"@tyj_heg__zhenzhe-draw",-cnum)
    end
  end
  local to = room:askForChoosePlayers(player,table.map(tos,Util.IdMapper),1,1,"#tyj__zhenzhe-invoke::"..data.to.id..":"..data.to.hp,self.name,true,true)
  for _, p in ipairs(tos) do
      room:setPlayerMark(p,"@tyj_heg__zhenzhe-dis",0)
      room:setPlayerMark(p,"@tyj_heg__zhenzhe-recover",0)
      room:setPlayerMark(p,"@tyj_heg__zhenzhe-draw",0)
  end
  if #to > 0 then
    self.cost_data = to[1]
    return true
  end
end
end,
on_use = function (self, event, target, player, data)
local room = player.room
local to = room:getPlayerById(self.cost_data)
room:doIndicate(player.id,{to.id})
local num = math.max(data.to.hp,0)
if to:isAlive() and #to:getCardIds('h')~=num then
  local n = #to:getCardIds('h') - num
    if n > 0 then
      local cards = room:askForDiscard(to, n, n, false, self.name, false,'.',"#tyj__zhenzhe-discard:::"..n,false,false)
      if #cards > 0 and to:isAlive() then
        room:recover({
          who = to,
          num = 1,
          recoverBy = player,
          skillName = self.name
        })
      end
    elseif n < 0 then
      player:drawCards(-n, self.name)
    end
end
end,
}
tyj__gongsundu:addSkill(tyj__zhenzhe)
Fk:loadTranslationTable{
  ["tyj_heg__zhenzhe"]="振詟",
  [":tyj_heg__zhenzhe"]="你使用【杀】或【决斗】对其他角色造成伤害后，可以令其攻击范围内的一名角色将手牌数调整至前者的体力值，若因此弃置了牌，后者回复1点体力。",
  ["#tyj__zhenzhe-invoke"]="是否发动 振詟 令 %dest 攻击范围内的一名角色将手牌数调整至 %arg 张？",
  ["#tyj__zhenzhe-discard"]="振詟:你需要弃置 %arg 张牌，因此弃置牌后回复1点体力",
  ["@tyj_heg__zhenzhe-draw"]="摸牌",
  ["@tyj_heg__zhenzhe-dis"]="弃牌",
  ["@tyj_heg__zhenzhe-recover"]="回复",
  ["$tyj_heg__zhenzhe1"] = "名震千里，泽被海东。",
  ["$tyj_heg__zhenzhe2"] = "施威除暴，上下咸服。",
  ["~tyj_heg__gongsundu"] = "为何都不愿出仕！",
}
local tyj__huangfusong = General(extension, "tyj_heg__huangfusong", "qun", 4,4)
tyj__huangfusong:addCompanions({"tyta_heg__zhujun"})
Fk:loadTranslationTable{
["tyj_heg__huangfusong"] = "皇甫嵩",
["#tyj_heg__huangfusong"] = "营火溃螟",
["designer:tyj_heg__huangfusong"] = "汤圆",
["cv:tyj_heg__huangfusong"] = "官方",
["illustrator:tyj_heg__huangfusong"] = "鬼画府",
}
local tyj__shiji = fk.CreateTriggerSkill{
  name = "tyj_heg__shiji",
  events={fk.AfterCardsMove,fk.EventPhaseStart},
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) then
        if event == fk.AfterCardsMove then
          for _, move in ipairs(data) do
            if #move.moveInfo>0 then
              if move.proposer and  move.proposer == player.id and move.moveReason == fk.ReasonDiscard and move.from then
              for _, info in ipairs(move.moveInfo) do
                if table.contains({Card.PlayerEquip,Card.PlayerHand},info.fromArea) then
                  return true
                end
            end
          end
        end
      end
    end
  end
  if event == fk.EventPhaseStart then
    return player:getMark('@@tyj_heg__shiji_used')~=0
  end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
     return room:askForSkillInvoke(player,self.name)
    elseif event == fk.EventPhaseStart then
      room:setPlayerMark(player,'@@tyj_heg__shiji_used',0)
      if player:isAlive() then
      local all_choices= {"#tyj_heg__shiji_use","#tyj_heg__shiji_fire"}
      local choice = {}
      local ids = {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    ids = table.filter(ids, function (id) return room:getCardArea(id) == Card.DiscardPile end)
    if #ids>0 then
      table.insert(choice,"#tyj_heg__shiji_use")
    end
      if #table.filter(room.alive_players, function(t)
        return U.canUseCardTo(room, player, t, Fk:cloneCard("fire_attack"))
    end)>0 then
      table.insert(choice,"#tyj_heg__shiji_fire")
    end
    if #choice>0 then
      local choice = room:askForChoice(player, choice, self.name,"势击：你可以选择一项执行",true,all_choices)
      if choice then
        self.cost_data = choice
        return true
      end
    end
  end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
    room:setPlayerMark(player,"@@tyj_heg__shiji_used",1)
    elseif event == fk.EventPhaseStart then
      if player:isAlive() then
      local choice = self.cost_data
      if choice == "#tyj_heg__shiji_use" then
        local ids = {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    ids = table.filter(ids, function (id) return room:getCardArea(id) == Card.DiscardPile end)
    if #ids>0 then
      local to = room:askForChoosePlayers(player,table.map(player.room:getOtherPlayers(player),Util.IdMapper),1,1,"势击：选择要使用牌的角色",self.name,false)
      if #to>0 then
      U.askForUseRealCard(room,room:getPlayerById(to[1]),ids, nil, self.name,"#tyj_heg__shiji_use-invoke", {expand_pile =ids, extra_use = true},false)
      end
    end
      elseif choice == "#tyj_heg__shiji_fire" then
        U.askForUseVirtualCard(room, player, "fire_attack", nil, self.name, "#tyj_heg__shiji_fire-invoke", true, false, false, false, nil,false)
      end
    end
    end
  end,
}
tyj__huangfusong:addSkill(tyj__shiji)
Fk:loadTranslationTable{
  ["tyj_heg__shiji"]="势击",
  [":tyj_heg__shiji"]="你弃置任意角色的牌后，你可以于下个阶段开始时选择一项：1.令一名其他角色使用一张本回合因弃置进入弃牌堆的牌；2.视为使用一张【火攻】。",
  ["#tyj_heg__shiji_use"]="令其他角色使用牌",
  ["#tyj_heg__shiji_use-invoke"]="势击：使用其中一张牌。",
  [":#tyj_heg__shiji_use"]="令一名其他角色使用一张本回合因弃置进入弃牌堆的牌",
  ["#tyj_heg__shiji_fire"]="使用【火攻】",
  [":#tyj_heg__shiji_fire"]="视为使用一张【火攻】",
  ["#tyj_heg__shiji_fire-invoke"]="势击：视为使用一张【火攻】",
  ["@@tyj_heg__shiji_used"]="势击",
  ["$tyj_heg__shiji1"]="敌军依草结营，正犯兵家大忌！",
  ["$tyj_heg__shiji2"]="兵法所云火攻之计，正合此时之势！",
  ["~tyj_heg__huangfusong"]="力有所能，臣必为也……",
}

local tyj__chendeng = General:new(extension, "tyj_heg__chendeng", "qun", 3,3)
    Fk:loadTranslationTable{
      ["tyj_heg__chendeng"] = "陈登",
      ["#tyj_heg__chendeng"] = "湖海豪士",
      ["designer:tyj_heg__chendeng"] = "汤圆",
      ["cv:tyj_heg__chendeng"] = "官方",
      ["illustrator:tyj_heg__chendeng"] = "游漫美绘",
    }

    local tyj__yingshui =fk.CreateTriggerSkill{
      name = "tyj_heg__yingshui",
  anim_type = "control",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.from == player.id and move.to and move.to ~= player.id and move.toArea == Card.PlayerHand then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              return true
            end
          end
        end
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    local tos = {}
    for _, move in ipairs(data) do
      if move.from == player.id and move.to and move.to ~= player.id and move.toArea == Card.PlayerHand then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            table.insertIfNeed(tos, move.to)
            break
          end
        end
      end
    end
    room:sortPlayersByAction(tos)
    for _, id in ipairs(tos) do
      if not player:hasSkill(self) then break end
      local to = room:getPlayerById(id)
      if to and not to.dead and not to:isNude() then
        self:doCost(event, to, player, data)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local can = room:askForSkillInvoke(player,self.name,nil,"#tyj_heg__yingshui-invoke::"..target.id)
    if can then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id,{target.id})
    local all_choices = {"#tyj_heg__yingshui-tomove","#tyj_heg__yingshui-toprohibit"}
    local choices = {}
    if #table.filter(Fk:currentRoom().alive_players, function(p) return target:canMoveCardsInBoardTo(p, 'e') end)>0 then
      table.insert(choices,"#tyj_heg__yingshui-tomove")
      end
      table.insert(choices,"#tyj_heg__yingshui-toprohibit")
      if #choices>0 then
        local result = room:askForChoice(target,choices,self.name,"#tyj_heg__yingshui-promt",false,all_choices)
        if result == "#tyj_heg__yingshui-tomove" then
          local targets = table.map(table.filter(player.room.alive_players, function(p)
            return target:canMoveCardsInBoardTo(p, nil)
          end), Util.IdMapper)
          if #targets > 0 then
            local to = room:askForChoosePlayers(player, targets, 1, 1, "#tyj_heg__yingshui-ask::" .. target.id, self.name, false)
            if #to > 0 then
              room:askForMoveCardInBoard(player, target, room:getPlayerById(to[1]), self.name, nil, target)
            end
          end
        else
          room:setPlayerMark(target,"@@tyj_heg__yingshui_prohibit-turn",1)
        end
      end
    end,
    }
    local tyj__yingshui_prohibit =fk.CreateProhibitSkill{
      name = "#tyj_heg__yingshui_prohibit",
      prohibit_use = function(self, player, card)
        return player:getMark("@@tyj_heg__yingshui_prohibit-turn") > 0
      end,
    }
    local tyj__fuyuan_active = fk.CreateViewAsSkill{
      name = "#tyj_heg__fuyuan_active",
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("befriend_attacking")
    card:addSubcards(cards)
    card.skillName = "tyj_heg__fuyuan"
    return card
  end,
    }
    local tyj__fuyuan = fk.CreateTriggerSkill{
      name = "tyj_heg__fuyuan",
      anim_type = "defensive",
      events = {fk.TargetConfirmed,fk.TurnEnd},
      can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self) then
          if event == fk.TargetConfirmed then
            return data.card and data.card.trueName == 'slash' and (target:getNextAlive() == player or player:getNextAlive() == target) and not player:isKongcheng()
          else
            return target == player and not player:isNude() and #table.filter(Fk:currentRoom().alive_players, function(p) return p:isKongcheng() and not H.compareKingdomWith(player,p) end)>0
          end
        end
      end,
      on_cost = function (self, event, target, player, data)
        local room = player.room
        if event == fk.TargetConfirmed then
          local cards = room:askForCard(player, 1, 1, false, self.name, true, ".", "#tyj_heg__fuyuan_slash-invoke::"..target.id)
    if #cards > 0 then
      self.cost_data = cards
      return true
    end
        else
          local success, dat = player.room:askForUseActiveSkill(player, "#tyj_heg__fuyuan_active", "#tyj_heg__fuyuan_end-invoke", true)
    if success then
      self.cost_data = dat
      return true
    end
        end
      end,
      on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.TargetConfirmed then
          room:doIndicate(player.id,{target.id})
          room:moveCardTo(self.cost_data, Card.PlayerHand, target, fk.ReasonGive, self.name,nil,false,player.id,nil,{player.id,target.id})
        else
          local room = player.room
          local card = Fk.skills["#tyj_heg__fuyuan_active"]:viewAs(self.cost_data.cards)
          local use = {
            from = player.id,
            tos = table.map(self.cost_data.targets, function(id) return {id} end),
            card = card,
          }
          room:useCard(use)
        end
      end,
    }
    local tyj__fuyuan_prohibit = fk.CreateProhibitSkill{
      name = "#tyj_heg__fuyuan_prohibit",
      is_prohibited = function(self, from, to, card)
          return table.contains(card.skillNames, "tyj_heg__fuyuan") and not to:isKongcheng()
      end,
    }
    tyj__yingshui:addRelatedSkill(tyj__yingshui_prohibit)
    tyj__fuyuan:addRelatedSkill(tyj__fuyuan_active)
    tyj__fuyuan:addRelatedSkill(tyj__fuyuan_prohibit)
    tyj__chendeng:addSkill(tyj__yingshui)
    tyj__chendeng:addSkill(tyj__fuyuan)
    Fk:loadTranslationTable{
      ["tyj_heg__yingshui"]="营说",
      [":tyj_heg__yingshui"]="其他角色获得你的牌后，你可以令其选择一项：1.令你移动其场上的一张牌；2.本回合不能再使用牌。",
      ["#tyj_heg__yingshui-invoke"]="是否对 %dest 发动 营说 ？",
      ["#tyj_heg__yingshui-promt"]="营说：请选择一项",
      ["#tyj_heg__yingshui-tomove"]="被移走牌",
      ["#tyj_heg__yingshui-toprohibit"]="不能使用牌",
      ["@@tyj_heg__yingshui_prohibit-turn"]="营说",
      ["#tyj_heg__yingshui-ask"]="营说：选择要将 %dest 场上的牌移动给的角色",
      ["#tyj_heg__yingshui_prohibit"]="营说",
      ["tyj_heg__fuyuan"]="扶援",
      [":tyj_heg__fuyuan"]="你的上下家成为【杀】的目标后，你可以交给其一张手牌。结束阶段，你可以将一张牌当【远交近攻】对一名没有手牌的角色使用。",
      ["#tyj_heg__fuyuan_slash-invoke"]="是否发动 扶援 交给 %dest 一张牌？",
      ["#tyj_heg__fuyuan_end-invoke"]="是否发动 扶援 将一张牌当【远交近攻】对一名没有手牌的角色使用？",
      ["#tyj_heg__fuyuan_prohibit"]="扶援",
      ["$tyj_heg__yingshui1"]="道之以德，齐之以礼。",
      ["$tyj_heg__yingshui2"]="施恩行惠，赡之以义。",
      ["$tyj_heg__fuyuan1"]="今君困顿，扶援相助。",
      ["$tyj_heg__fuyuan2"]="恤君之患，以相扶援。",
      ["~tyj_heg__chendeng"]="吾疾无人可治。",
    }
return extension